/**
 * Created with CLion.
 * Description: 
 * User: loong
 * Date: 2019-12-28
 * Time: 20:52
 */
#include "DBHelper.h"

int DBHelper::conn() {
    //创建数据库  并使用默认连接
    QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("39.97.107.200");
    db.setDatabaseName("plantsinfo");
    db.setUserName("root");
    db.setPassword("123456");
    //打开数据库
    if(!db.open()){
        qDebug()<<"Cannot open database\n";
        //QMessageBox::critical(0,"Cannot open database", "Unable to establish a database connection", QMessageBox::Cancel);
        return 1;
    }else{
        qDebug()<<"Database connection established";
        return 0;
    }
}